import pygame
import random



def gen_point():
    x = random.randint(20, 480)
    points.append([x, 0])

pygame.init()
screen = pygame.display.set_mode((500, 500))
rect = pygame.rect.Rect(200,400, 100, 30)
points = []
clock = pygame.time.Clock()
pygame.time.set_timer(pygame.USEREVENT, 1)
while True:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
        if event.type == pygame.USEREVENT:
            gen_point()
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_LEFT:
                rect.x = rect.x-5
            elif event.key == pygame.K_RIGHT:
                rect.x = rect.x+5

    screen.fill((0,0,0))
    for point in points:
        pygame.draw.circle(screen, (255, 0, 0), point, 20)
        point[1] += 2

    pygame.draw.rect(screen, (0, 255, 0), rect)
    clock.tick(800)
    pygame.display.update()
